home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 18 / fpc103.zip / SEARCH.SEQ < prev    next >
Text File  |  1988-06-28  |  2KB  |  68 lines

  1. \ SEARCH.SEQ    String search routine.                  by Roger Bird
  2.  
  3. comment:
  4.  
  5.   This file may be removed, but it is used by WORDS.SEQ, and ENVIRON.SEQ,
  6. which is itself used by EXEC.SEQ.
  7.  
  8.   The String manipulation primitives include string comparison and
  9. searching. The string search implemented is used in the editor
  10. to find the desired string.  The only unusual thing about it is
  11. the presence of a variable called CAPS, which determines
  12. whether or not to ignore the case of the subject and pattern
  13. strings.  If case is ignored then A-Z = a-z.  The default is
  14. ignore case.
  15.  
  16.         Much thanks to Roger Bird for this improved impilmentation
  17.         of SEARCH, it is about 20 % faster than my previous improved
  18.         version, and is 10 times faster in the case where the string
  19.         being searched for starts with a space. It is also 140 bytes
  20.         smaller than the old implimentation.
  21.  
  22. comment;
  23.  
  24. hex
  25. CODE SEARCH     ( sadr slen dadr dcnt -- offset found? )
  26.   pop cx   pop di
  27.   pop bx   pop ax   push di
  28.   push es   mov es, sseg   push si   push bp   mov si, ax
  29.   dec bx
  30.   mov dx, bx    cmp caps # 0
  31.   0= if    mov bp, # 0
  32.      else  mov bp, # $2020
  33.      then
  34.   begin
  35.       cmp bx, cx
  36.   <= while
  37.       begin
  38.           mov al, 0 [si+bx]   mov ah, es: 0 [di+bx]
  39.           or ax, bp   cmp ah, al
  40.       0= while  dec bx  0< if     pop bp   pop si   pop es
  41.                                   pop dx   sub di, dx
  42.                                   push di  mov ax, # $FFFF   1push
  43.                           then
  44.       repeat
  45.       inc di   dec cx   mov bx, dx
  46.   repeat
  47.   pop bp      pop si       pop es
  48.   pop dx      sub di, dx   push di
  49.   sub ax, ax  1push
  50.   end-code
  51.  
  52. decimal
  53.  
  54. comment:
  55.  
  56. : DELETE   ( buffer size count -- )
  57.    OVER MIN >R  R@ - ( left over )  DUP 0>
  58.    IF  2DUP SWAP DUP R@ + -ROT SWAP CMOVE  THEN  + R> BLANK ;
  59.  
  60. : INSERT   ( string length buffer size -- )
  61.    ROT OVER MIN >R  R@ - ( left over )
  62.    OVER DUP R@ +  ROT CMOVE>   R> CMOVE  ;
  63.  
  64. : REPLACE   ( string length buffer size -- )  ROT MIN CMOVE ;
  65.  
  66. comment;
  67.  
  68.